//方法一：malloc法
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;

    // write your code here.....
    int **p = (int**)malloc(sizeof(int*) * n);
    for(int i = 0; i < n; i++){
        p[i] = (int*)malloc(sizeof(int) * n);
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            p[i][j] = i + j;
            cout << p[i][j] << " ";
        }
        cout << endl;
    }
    for(int i = 0; i < n; i++){
        free(p[i]);
    }
    return 0;
}

//new法
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;

    // write your code here......
    int **p = new int* [n];
    for(int i = 0; i < n; i++){
        p[i] = new int[n];
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            p[i][j] = i + j;
            cout << p[i][j] << " ";
        }
        cout << endl;
    }
    for(int i = 0; i < n; i++){
        delete [] p[i];
    }
    return 0;
}

/*输入一个正整数n，创建大小为n∗n的二维数组a（采用动态数组的方式），将a[i][j]初始化为i+j(0≤i<n,0≤j<n)。并输出数组中的元素。*/